import functools
from typing import Callable
from src.logger import llm_logger
import traceback


def langgraph_decorator(func: Callable):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        error_info = None
        try:
            result = func(*args, **kwargs)
            return result
        except Exception as e:
            error_info = e
            stack_trace = traceback.print_exc()
            llm_logger.error(f"error: {str(e)}\n{stack_trace}")
            return {"error": error_info.__str__()}

    return wrapper
